package cn.netjava.softkid.chapter08;

import java.util.Iterator;
import java.util.Vector;

public class VectorDemo {
	/**
	 * constructor method
	 * initialize a new vector 
	 */
	public VectorDemo()
	{
		v = new Vector<Object>();
	}
	/**
	 * add element to the vector
	 * @param obj: element to be add
	 */
	public void addElement(Object obj)
	{
		v.add(obj);
	}
	/**
	 * delete element in the vector
	 * @param index: position of element to be delete
	 */
	public void deleteElement(int index)
	{
		v.remove(index);
	}
	/**
	 * delete element in the vector
	 * @param obj: element to be delete
	 */
	public void deleteElement(Object obj)
	{
		v.remove(obj);
	}
	/**
	 * find element to see if in the vector
	 * @param obj: element to be find 
	 */
	public void findElementPosition(Object obj)
	{
			if(v.indexOf(obj)==-1)
			{
				System.out.println("Element not found!");
			}
			else
			{
				System.out.println(v.indexOf(obj));
			}
	}
	
	/**
	 * output all elements in the vector
	 */
	public void outputAllElements()
	{
		Iterator<Object> iter = v.iterator();
		while(iter.hasNext())
		{
			System.out.println(iter.next());
		}
	}
	
	private Vector<Object> v;	 
}
